home *** CD-ROM | disk | FTP | other *** search
-
- /*© Copyright 1988-1992 UserLand Software, Inc. All Rights Reserved.*/
-
-
- #include "appletstrings.h"
- #include "appletfont.h"
- #include "appletmouse.h"
- #include "appletquickdraw.h"
- #include "appletops.h"
- #include "appletcursor.h"
- #include "appletpopup.h"
-
-
-
- #define popuparrowwidth 16
-
- #define drawinset 5
-
- static short trackericonnum;
-
- static Rect trackerrect;
-
-
-
-
- boolean pushpopupitem (typopuprecord *popup, bigstring bs, boolean flenabled) {
-
- register MenuHandle hmenu = (*popup).hmenu;
- bigstring bsspace;
-
- if (equalstrings (bs, "\p(-")) /*take disabled seperator as is*/
- AppendMenu (hmenu, bs);
-
- else { /*to allow meta-characters in bs, append blank item, then set item text*/
-
- setstringwithchar (chspace, bsspace);
-
- AppendMenu (hmenu, bsspace);
-
- if (!isemptystring (bs))
- SetItem (hmenu, CountMItems (hmenu), bs);
- }
-
- if (!flenabled)
- DisableItem (hmenu, CountMItems (hmenu));
-
- return (true);
- } /*pushpopupitem*/
-
-
- static void displaypopupicon (Rect r, boolean flenabled) {
-
- register short iconnum;
-
- if (flenabled)
- iconnum = 0;
- else
- iconnum = 1;
-
- plotsmallicon (r, 129, iconnum, false);
- } /*displaypopupicon*/
-
-
- void drawpopup (typopuprecord *popup) {
-
- Rect rpopup = (*popup).popuprect;
- bigstring bs;
- Rect r;
- RGBColor rgb;
-
- pushbackcolor (whiteindex);
-
- r = rpopup;
-
- r.bottom++;
-
- r.right++;
-
- r = rpopup;
-
- EraseRect (&r);
-
- r = rpopup;
-
- InsetRect (&r, 1, 1);
-
- r.left = r.right - popuparrowwidth;
-
- displaypopupicon (r, true);
-
- r = rpopup;
-
- FrameRect (&r);
-
- MoveTo (r.left + 1, r.bottom);
-
- LineTo (r.right, r.bottom);
-
- LineTo (r.right, r.top + 1);
-
- r.right -= popuparrowwidth;
-
- InsetRect (&r, 4, 2);
-
- pushstyle (geneva, 9, 0);
-
- MoveTo (r.left, r.bottom - globalfontinfo.descent - 1);
-
- copystring ((*popup).bs, bs);
-
- ellipsize (bs, r.right - r.left);
-
- DrawString (bs);
-
- popstyle ();
-
- zerorect (&(*popup).leftarrowrect);
-
- zerorect (&(*popup).rightarrowrect);
-
- if ((*popup).flarrows) {
-
- r = rpopup;
-
- r.right = r.left - drawinset;
-
- r.left = r.right - widthsmallicon;
-
- OffsetRect (&r, 2, 1); /*move it right by two pixels, down by one pixel*/
-
- (*popup).leftarrowrect = r;
-
- plotsmallicon (r, 128, 1, false);
-
- r = rpopup;
-
- r.left = r.right + drawinset;
-
- r.right = r.left + widthsmallicon;
-
- OffsetRect (&r, -2, 1); /*move it left by two pixels, down by one pixel*/
-
- (*popup).rightarrowrect = r;
-
- plotsmallicon (r, 128, 0, false);
- }
-
- popbackcolor ();
- } /*drawpopup*/
-
-
- static void icontracker (boolean flpressed) {
-
- /*
- callback routine for the mouse tracker.
- */
-
- register short iconnum = trackericonnum;
-
- if (flpressed)
- iconnum += 2;
-
- pushbackcolor (lighterblueindex);
-
- EraseRect (&trackerrect);
-
- plotsmallicon (trackerrect, 128, iconnum, false);
-
- popbackcolor ();
- } /*icontracker*/
-
-
- static boolean arrowtracker (Rect r, popupcallback arrowcallback) {
-
- trackerrect = r;
-
- icontracker (true); /*display button in its pressed state*/
-
- if (mousetrack (r, &icontracker)) {
-
- icontracker (false); /*display button in its un-pressed state*/
-
- (*arrowcallback) ();
- }
-
- return (true);
- } /*arrowtracker*/
-
-
- boolean popupclick (typopuprecord *popup) {
-
- if (PtInRect (mousestatus.localpt, &(*popup).leftarrowrect)) {
-
- trackericonnum = 1;
-
- arrowtracker ((*popup).leftarrowrect, (*popup).leftarrowcallback);
-
- return (true);
- }
-
- if (PtInRect (mousestatus.localpt, &(*popup).rightarrowrect)) {
-
- trackericonnum = 0;
-
- arrowtracker ((*popup).rightarrowrect, (*popup).rightarrowcallback);
-
- return (true);
- }
-
- if (PtInRect (mousestatus.localpt, &(*popup).popuprect)) {
-
- register MenuHandle hmenu;
- Point pt;
-
- if (!(*popup).getmenucallback ()) /*error, but consume the mouse click*/
- return (true);
-
- hmenu = (*popup).hmenu;
-
- CheckItem (hmenu, (*popup).checkeditem, true);
-
- InsertMenu (hmenu, -1); /*see IM-V, p 236*/
-
- setcursortype (cursorisarrow); /*arrow cursor is more appropriate here*/
-
- pt.v = (*popup).popuprect.top;
-
- pt.h = (*popup).popuprect.left;
-
- if ((*popup).checkeditem == 0) { /*no item selected*/
-
- CalcMenuSize (hmenu);
-
- pt.v -= (**hmenu).menuHeight / 2;
- }
-
- LocalToGlobal (&pt);
-
- pushstyle (geneva, 9, 0);
-
- (*popup).itemselected = LoWord (PopUpMenuSelect (hmenu, pt.v, pt.h, (*popup).checkeditem));
-
- popstyle ();
-
- (*popup).menuselectcallback ();
-
- DeleteMenu ((*popup).idmenu);
-
- DisposeMenu (hmenu);
-
- return (true);
- }
-
- return (false);
- } /*popupclick*/
-
-
- boolean adjustpopupcursor (typopuprecord *popup) {
-
- if (!PtInRect (mousestatus.localpt, &(*popup).popuprect))
- return (false);
-
- setcursortype (cursorispopup);
-
- return (true);
- } /*adjustpopupcursor*/
-
-
-
-
-